<template>
  <div class="app-container">
    <el-tabs v-model="listQuery.status" type="card" style="margin-bottom:10px">
      <el-tab-pane v-for="item in jcRegStatusJson" :key="item.value" :label="item.label" :name="item.value+''">
      </el-tab-pane>
    </el-tabs>
    <div class="filter-container">
      <el-input v-model="listQuery.biddingIdentifier" placeholder="竞价编号" class="filter-item" clearable/>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter" >
        查询
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row row-key="id" style="width: 100%;">
      <el-table-column label="序号" type="index" align="center" width="60px" />
      <el-table-column label="竞价编号" prop="biddingIdentifier" align="center" />
      <el-table-column label="企业名称" prop="companyName" align="center" />
      <el-table-column label="产品名称" prop="name" align="center" />
      <el-table-column label="单位" prop="unit" align="center" />
      <el-table-column label="竞拍价格" prop="price" align="center" />
      <el-table-column label="起拍价" prop="topPrice" align="center" />
      <el-table-column label="竞拍数量" prop="topNum" align="center">
        <template slot-scope="{row}">
          {{ row.topNum + row.unit }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" align="center" />
      <el-table-column label="状态" prop="statusText" align="center" >
        <template slot-scope="{row}">
          <el-tag :type="row.status | statusFilter">
            {{ row.statusText }}
          </el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220px">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleCancel(row)" v-if="row.status === 2>
            取消竞价
          </el-button>
          <el-button size="mini" @click="handleDetail(row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize"
      @pagination="getList" />

    <el-dialog title="详情" :visible.sync="dialogDetailVisible" width="888px" v-if="detail">
      <el-row :gutter="40">
        <el-col :span="8">
          竞价编号：
          <span style="font-size:13px">{{detail.identifier}}</span>
        </el-col>
        <el-col :span="8">创建时间：{{detail.createTime}}</el-col>
        <el-col :span="8">订单状态：{{detail.statusText}}</el-col>
      </el-row>
      <el-row :gutter="40">
        <el-col :span="8">起拍价：{{detail.topPrice}}</el-col>
        <el-col :span="16">竞价时间：{{detail.startDate}}至{{detail.endDate}}</el-col>
      </el-row>
      <el-row :gutter="40">
        <el-col :span="8">最新价格：{{detail.newPrice}}</el-col>
        <el-col :span="8">出价次数：{{detail.priceTimes}}</el-col>
      </el-row>
      <el-card style="margin:20px 0" shadow="hover">
        <div slot="header" class="clearfix">
          <span>竞价明细</span>
        </div>
        <el-table :data="detail.details" style="width: 100%" border fit highlight-current-row row-key="id">
          <el-table-column label="企业名称" prop="companyName" align="center" />
          <el-table-column label="企业联系电话" prop="companyContactMobile" align="center" />
          <el-table-column label="竞拍价格" prop="price" align="center" />
          <el-table-column label="起拍价" prop="topPrice" align="center" />
          <el-table-column label="竞价时间" prop="createTime" align="center" />
        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogDetailVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogDetailVisible = false">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { biddingDetailPageByQo, biddingGetById } from '@/api/transaction'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { jcRegStatusJson } from '../constant'
import NumInput from '@/components/NumInput'
import DatePicker from '@/components/DatePicker'

export default {
  name: "TransactionGroupBuying",
  directives: { waves },
  components: { Pagination, NumInput, DatePicker },
  filters: {
    statusFilter(status) { //状态
      const statusMap = {
        2: '',
        3: 'success',
        99: 'danger',
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        status: "2",
        pageNo: 1,
        pageSize: 20,
        biddingIdentifier: ""
      },
      jcRegStatusJson,
      dialogDetailVisible: false,
      detail: {}
    };
  },
  watch: {
    "listQuery.status": function () {
      this.handleFilter();
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      biddingDetailPageByQo(this.listQuery).then(response => {
        this.list = response.list || [];
        this.total = response.totalCount;
        this.listLoading = false;
      });
    },
    handleFilter() {
      this.listQuery.pageNo = 1;
      this.getList();
    },
    handleDetail(row) {
      this.getDetail(row.id).then(res => {
        this.detail = Object.assign({}, res);
        this.dialogDetailVisible = true;
      });
    },
    getDetail(id) {
      return new Promise((resolve, reject) => {
        biddingGetById(id)
          .then(res => {
            resolve(res);
          })
          .catch(err => {
            reject(err);
          });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.el-row {
  line-height: 2;
  font-size: 15px;
}
</style>